package com.zhuojy.equity.mall.admin.web.controller;

import com.zhuojy.equity.mall.admin.common.entity.Accounts;
import com.zhuojy.equity.mall.admin.common.pojo.JsonResult;
import com.zhuojy.equity.mall.admin.service.AccountsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资金账户
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("Accounts")
@Api(tags = "资金账户")
public class AccountsController {
    @Autowired
    private AccountsService accountsService;

    /**
     * 资金账户条查分页
     */
    @ApiOperation(value = "资金账户条查分页", httpMethod = "POST", notes = "资金账户条查分页")
    @RequestMapping("findAccountsPagination")
    public JsonResult findAccountsPagination(@RequestBody Accounts accounts, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return accountsService.findAccountsPagination(accounts, pageNum, pageSize);
    }


    /**
     * 资金账户状态停用
     */
    @ApiOperation(value = "资金账户状态停用", httpMethod = "POST", notes = "资金账户状态停用")
    @RequestMapping("updateStatusting")
    public JsonResult updateStatusting(Integer id) {
        try {
            accountsService.updateStatusting(id);
            return JsonResult.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success("修改失败");
        }
    }

    /**
     * 资金账户状态停用
     */
    @ApiOperation(value = "资金账户状态启用", httpMethod = "POST", notes = "资金账户状态启用")
    @RequestMapping("updateStatusqi")
    public JsonResult updateStatusqi(Integer id) {
        try {
            accountsService.updateStatusqi(id);
            return JsonResult.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success("修改失败");
        }
    }
    /**
     * 资金账户动态下拉列表框
     */
    @ApiOperation(value = "资金账户动态下拉列表框", httpMethod = "POST", notes = "资金账户动态下拉列表框")
    @RequestMapping("findOptions")
    public List<Accounts> findOptions(){
       return accountsService.findOptions();
    }
    /**
     * 资金账户新增
     */
    @ApiOperation(value = "资金账户新增", httpMethod = "POST", notes = "资金账户新增")
    @RequestMapping("addAccounts")
    public JsonResult addAccounts(@RequestBody Accounts accounts){
        try {
            accountsService.addAccounts(accounts);
            return JsonResult.success(200,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"新增失败");
        }
    }
    /**
     * 资金账户回显
     */
    @ApiOperation(value = "资金账户回显", httpMethod = "POST", notes = "资金账户回显")
    @RequestMapping("findAccountsById")
    public Accounts findAccountsById(Integer id){
        return accountsService.findAccountsById(id);
    }
    /**
     * 资金账户修改
     */
    @ApiOperation(value = "资金账户修改", httpMethod = "POST", notes = "资金账户修改")
    @RequestMapping("updateAccounts")
    public JsonResult updateAccounts(@RequestBody Accounts accounts){
        try {
            accountsService.updateAccounts(accounts);
            return JsonResult.success(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"修改失败");
        }
    }
    /**
     * 修改为默认
     */
    @ApiOperation(value = "修改为默认", httpMethod = "POST", notes = "修改为默认")
    @RequestMapping("updateDefault")
    public JsonResult updateDefault(@RequestParam("id") Long id){
        try {
            accountsService.updateDefault(id);
            return JsonResult.success(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"修改失败");
        }
    }
}
